package com.stormrage.edu.serv.student.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stormrage.edu.dao.student.StuAcctDao;
import com.stormrage.edu.serv.student.StuAcctServ;
import com.stormrage.entity.student.StuAcct;
import com.stormragetech.core.exception.StormrageTechException;
import com.stormragetech.core.util.SecureUtil;

@Service
public class StuAcctServImpl implements StuAcctServ {

	private static final Logger logger = LoggerFactory.getLogger(StuAcctServImpl.class);

	@Autowired
	private StuAcctDao stuAcctDao;

	@Override
	public void editPass(final Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Service 】- 【 StuAcctServ 】- 【 editPass 】- 【 STARTED 】");

		StuAcct entity = queryById(arg0);

		logger.debug(" acctid >>>>>> " + arg0);

		entity.setSalt(SecureUtil.initUUID());
		entity.setPass(SecureUtil.initPass("123456", entity.getSign()));

		logger.debug(" salt >>>>>> " + entity.getSalt());
		logger.debug(" pass >>>>>> " + entity.getPass());

		updatePass(entity);

		logger.debug(" 【 Service 】- 【 StuAcctServ 】- 【 editPass 】- 【 COMPLETED 】");

	}

	@Override
	public void updatePass(final StuAcct arg0) throws StormrageTechException {

		logger.debug(" 【 Service 】- 【 StuAcctServ 】- 【 update 】- 【 STARTED 】");

		stuAcctDao.updatePass(arg0);

		logger.debug(" 【 Service 】- 【 StuAcctServ 】- 【 update 】- 【 COMPLETED 】");

	}

	@Override
	public StuAcct queryById(Integer arg0) throws StormrageTechException {

		logger.debug(" 【 Service 】- 【 StuAcctServ 】- 【 queryById 】- 【 STARTED 】");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", arg0);

		StuAcct entity = stuAcctDao.queryById(map);

		logger.debug(" 【 Service 】- 【 StuAcctServ 】- 【 queryById 】- 【 COMPLETED 】");
		return entity;

	}

}
